home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 2 / Macwelt DVD 2.cdr / Audio-Video-Multimedia / macos9 / Athena CL 1.0.13 / CLdialogs.py / CLdialogs.py
Encoding:
Text File  |  2002-03-15  |  26.1 KB  |  738 lines  |  [TEXT/Pyth]

  1. # CLdialogs.py
  2. #-----------------------------------------------------------------||||||||||||--
  3. # Copyright (c) 2001 Christopher Ariza.
  4. # athenaCL comes with ABSOLUTELY NO WARRANTY;
  5. # for details see waranty information within athenaObj.py.
  6. # This is free software, and you are welcome to redistribute it under certain  
  7. # conditions; for details see copyright information within athenaObj.py.
  8. #-----------------------------------------------------------------||||||||||||--
  9.  
  10.  
  11. import sys, os, copy
  12.  
  13. def update_visualMethod():
  14.    reload(os)
  15.    if os.name == 'mac':
  16.       import macfs
  17.       osVisualMethod = 'mac'
  18.    elif os.name == 'posix':
  19.       try:      
  20.          import Tkinter
  21.          Tkinter.Tk
  22.          import tkFileDialog
  23.          osVisualMethod = 'tkWin'
  24.       except:
  25.          osVisualMethod = 'text'#default, good on all platforms
  26.    else:  # all windows flavors
  27.       try:      
  28.          import Tkinter
  29.          Tkinter.Tk
  30.          import tkFileDialog
  31.          osVisualMethod = 'tkWin'
  32.       except:
  33.          osVisualMethod = 'text'#default, good on all platforms
  34.    return osVisualMethod
  35.  
  36.  
  37. #-----------------------------------------------------------------||||||||||||--
  38. ### utility functions
  39.  
  40. # this version is different from that in athenaCL.py
  41. def print_topics(header, cmds, cmdlen, maxcol, outLine='off'):
  42.  
  43.    if header == '':
  44.       ruler = ''
  45.    else:
  46.       ruler = '_'
  47.    if cmds:
  48.       max_len = 0
  49.       for name in cmds:
  50.          if len(name) >= max_len:
  51.             max_len = len(name)
  52.       if cmdlen == 0:
  53.          cmdlen = max_len + 2 # buffer space
  54.       else:
  55.          pass
  56.       if header != '':
  57.          print header
  58.       if ruler != '':
  59.          print ruler * 70
  60.       (cmds_per_line, junk) = divmod(maxcol, cmdlen)
  61.       col = cmds_per_line
  62.       for cmd in cmds:
  63.          cmd = cmd.strip()
  64.          if col == 0:
  65.             print ''
  66.             if outLine != 'off': ## only if special mode is desired
  67.                if cmd != cmds[0]: # if not the first
  68.                   print (('%-'+`cmdlen`+'s') % ' '), # add white space
  69.                   col = (col+1) % cmds_per_line # shit col but dont skip cmd
  70.          print (('%-'+`cmdlen`+'s') % cmd),
  71.          col = (col+1) % cmds_per_line
  72.       print ''
  73.  
  74.  
  75. #-----------------------------------------------------------------||||||||||||--
  76. ### general dialogs
  77.  
  78. def Message(string):
  79.    string.strip()
  80.    print string   
  81.  
  82. #-----------------------------------------------------------------||||||||||||--
  83. def AskString(q_string, sessionType='terminal', parentGUI=None):
  84.    if sessionType == 'terminal' or sessionType == 'IDLE':
  85.       q_string = q_string + ' ' #this might have been causing spacing problems on return cariages
  86.       a_string = raw_input(q_string)
  87.       a_string.strip()
  88.       return a_string
  89.    elif sessionType == 'Tkinter':
  90.       import dlgTk
  91.       returnString = dlgTk.askstring("dlg", q_string, parent=parentGUI)
  92.       if returnString == None:
  93.          returnString = ''
  94.       print '%s %s' % (q_string, returnString), # show user history
  95.       return returnString
  96.  
  97. def AskYesNoCancel(quary, default_selection=1, sessionType='terminal', parentGUI=None):
  98.    if sessionType == 'terminal' or sessionType == 'IDLE':
  99.       while 1:
  100.          ### 1 for yes, 0 for no, -1 for cancel
  101.          q_string = quary + '(y, n, or cancel): '
  102.          a_string = raw_input(q_string)
  103.          status = -2
  104.          if a_string.find('-1') >= 0 or a_string.find('c') >= 0 or a_string.find('C') >= 0:
  105.             status = -1
  106.             break
  107.          elif a_string.find('1') >= 0 or a_string.find('y') >= 0 or a_string.find('Y') >= 0:
  108.             status = 1
  109.             break
  110.          elif a_string.find('0') >= 0 or a_string.find('n') >= 0 or a_string.find('N') >= 0:
  111.             status = 0
  112.             break
  113.          else:
  114.             print '   unidentified input, please try again:'
  115.             continue
  116.       return status
  117.    elif sessionType == 'Tkinter':
  118.       import dlgTk
  119.       while 1:
  120.          ### 1 for yes, 0 for no, -1 for cancel
  121.          quary = quary + '(y, n, or cancel): '
  122.          a_string = dlgTk.askstring("dlg", quary, parent=parentGUI)
  123.          if a_string[-1:] == '\n\n': # watch for extra end-lines
  124.             a_string = a_string[-1:]
  125.          status = -2
  126.          if a_string == None:
  127.             a_string = ''
  128.             status = -1 # canceled
  129.             break
  130.          if a_string.find('-1') >= 0 or a_string.find('c') >= 0 or a_string.find('C') >= 0:
  131.             status = -1
  132.             break
  133.          elif a_string.find('1') >= 0 or a_string.find('y') >= 0 or a_string.find('Y') >= 0:
  134.             status = 1
  135.             break
  136.          elif a_string.find('0') >= 0 or a_string.find('n') >= 0 or a_string.find('N') >= 0:
  137.             status = 0
  138.             break
  139.          else:
  140.             print '   unidentified input, please try again:'
  141.             continue
  142.       print '%s%s' % (quary, a_string), # show user history
  143.       return status
  144.  
  145.  
  146. #-----------------------------------------------------------------||||||||||||--
  147. ### general files service functioins
  148. def CheckDirPath(test_path):
  149.    ### check for double_sep
  150.    double_sep = os.sep + os.sep
  151.    if test_path[-2:] == double_sep:
  152.       test_path = test_path[:-2]
  153.    return test_path
  154.  
  155. def GetDirectory(prompt='please select a directory:', sample_dir=''):
  156.    osVisualMethod = update_visualMethod()
  157.    ### returns 0 if canceled or quit, otherwise 1
  158.    ### platform specific file dialogs.
  159.    if osVisualMethod == 'mac':
  160.       import macfs
  161.       fsspec, ok = macfs.GetDirectory(prompt)
  162.       if ok != 1:
  163.          return '', 0
  164.       path = fsspec.as_pathname()
  165.       os.path.normpath(path)
  166.       return path, 1
  167.  
  168.    ### platform specific file dialogs.
  169.    if osVisualMethod == 'tkWin':
  170.       import Tkinter
  171.       import tkFileDialog
  172.       tkTemp = Tkinter.Tk()
  173.       tkTemp.withdraw()
  174.       options  = {'filetypes':[("directory", "*")], ## "dir" only shows directories, but are unable to select 
  175.                  'initialdir': sample_dir,
  176.                   'title'    : prompt,     
  177.                   'parent'   : tkTemp}
  178.       guiTemp = tkFileDialog.Open()
  179.       guiTemp.options = options
  180.       # filename = apply(tkFileDialog.Open, (), options).show(
  181.       pathToFile = guiTemp.show()
  182.       # clean up gui mess
  183.       del guiTemp
  184.       tkTemp.destroy()
  185.       # return path
  186.       if pathToFile != '' and pathToFile != None:
  187.          pathToFile = os.path.dirname(pathToFile)  ### remove file name
  188.          pathToFile = os.path.normpath(pathToFile)
  189.          return pathToFile, 1
  190.       else:
  191.          return '', 0
  192.  
  193.    ### for all other platforms, osVisualMethod == text
  194.    if sample_dir == '':
  195.       current_dir = CheckDirPath(os.getcwd())
  196.    else:
  197.       if os.path.isdir(sample_dir) != 1:  # if this path is not a directory
  198.          current_dir = CheckDirPath(os.getcwd())
  199.       else:
  200.          current_dir = sample_dir
  201.    final_path = ''
  202.  
  203.    while 1:
  204.       #current_dir  = CheckDirPath(current_dir)
  205.       cwd_contents = os.listdir(current_dir)
  206.       header = '%s' % current_dir #delete extra space here
  207.       print_topics(header, cwd_contents, 0, 72)
  208.       print prompt
  209.       menu_items = 'change directory menu: enter name, .., path, cancel or select (c or s):'
  210.       test_path  = AskString(menu_items)
  211.       final_path = ''
  212.  
  213.       ### scan for each of the options
  214.       # if entry is s, return cwd
  215.       if test_path == 's' or test_path == 'S':
  216.          final_path  = current_dir
  217.       # go up to next higher directory, display contents
  218.       if test_path == '..':
  219.          pathValid = os.path.exists(current_dir)
  220.          up_dir    = os.path.dirname(current_dir)
  221.          ### up_dir = CheckDirPath(up_dir)
  222.          current_dir = up_dir
  223.          continue
  224.       # if entry is the name of a dir in the cwd, then display contents and make cwd
  225.       if final_path == '':
  226.          down_dir = os.path.join(current_dir, test_path)
  227.          down_dir = os.path.normpath(down_dir)
  228.          down_dir = CheckDirPath(down_dir)
  229.          cwd_contents = os.listdir(current_dir)
  230.          if test_path in cwd_contents:
  231.             if os.path.isdir(down_dir) != 1: # if not a dir
  232.                print '   to select a file, first select this directory by entering "s".'
  233.                continue
  234.             else:
  235.                current_dir = down_dir
  236.                continue
  237.       # check if the user has entered a complete path
  238.       if final_path == '':
  239.          complete_path = CheckDirPath(test_path)
  240.          if os.path.exists(complete_path) == 1 and os.path.isdir(complete_path) == 1: #true if is a directory.:
  241.             current_dir = complete_path
  242.             continue        
  243.       # final test
  244.       if final_path == '':
  245.          if test_path == 'c' or test_path == 'C':
  246.             return '', 0
  247.          else:
  248.             print '   %s not understood.' % test_path
  249.             continue
  250.          
  251.       if os.path.exists(final_path) != 1:
  252.          status = AskYesNoCancel('   this is not a valid path. try again? ')
  253.          if status != 1:
  254.             return '', 0
  255.          else:
  256.             continue
  257.       else:
  258.          #ok = AskYesNoCancel(' CD: %s\n   ' % final_path)
  259.          #if ok == -1:
  260.          final_path = os.path.normpath(final_path)
  261.          return final_path, 1
  262.  
  263.  
  264. def StandardPutFile(prompt='please name this file:', defaultFilename='name', defaultDirectory='', extension='*'):
  265.    osVisualMethod = update_visualMethod()
  266.  
  267.    ### platform specific file dialogs.
  268.    if osVisualMethod == 'mac':
  269.       import macfs
  270.       fsspec, ok = macfs.StandardPutFile(prompt, defaultFilename)
  271.       if ok != 1:
  272.          return '', 0
  273.       path = fsspec.as_pathname()
  274.       ## check extension, add if missing
  275.       path = os.path.normpath(path)
  276.       return path, 1
  277.  
  278.    ### platform specific file dialogs.
  279.    if osVisualMethod == 'tkWin':
  280.       import Tkinter
  281.       import tkFileDialog
  282.       tkTemp  = Tkinter.Tk()
  283.       tkTemp.withdraw()
  284.       options  = {'filetypes':[("all files", "*")],   ### put extension here, but dont know if i need period or not
  285.                  'initialdir': defaultDirectory,
  286.                   'title'    : prompt,     
  287.                   'parent'   : tkTemp}
  288.       guiTemp = tkFileDialog.SaveAs()
  289.       guiTemp.options = options
  290.       # filename = apply(tkFileDialog.Open, (), options).show(
  291.       path = guiTemp.show()
  292.       # clean up gui mess
  293.       del guiTemp
  294.       tkTemp.destroy()
  295.       # return path
  296.       if path != '' and path != None:
  297.          path = os.path.normpath(path)
  298.          return path, 1
  299.       else:
  300.          return '', 0
  301.  
  302.  
  303.    ### for all other platforms
  304.    final_path = ''
  305.    status = 0
  306.    directory = defaultDirectory
  307.    while 1:
  308.       ### get file name
  309.       test_filename = AskString('%s' % prompt)
  310.       if directory == '':
  311.          directory = CheckDirPath(os.getcwd())
  312.       else:
  313.          directory = CheckDirPath(directory)
  314.  
  315.       ### get directory
  316.       status = AskYesNoCancel('%s\n   save in this directory? ' % directory)
  317.       if status == -1:  #cancel
  318.          break
  319.       if status == 0:   #no, get new directory
  320.          path, ok = GetDirectory('', directory)
  321.          if ok != 1:
  322.             status = -1
  323.             break
  324.          else:
  325.             directory = path
  326.             status = 1
  327.  
  328.       if status == 1:
  329.       ### test for existing file 
  330.          dir_contents = os.listdir(directory)
  331.          if test_filename in dir_contents:
  332.             ok = AskYesNoCancel('this file already exists. replace? ')
  333.             if ok != 1:
  334.                continue
  335.       final_path = os.path.join(directory,test_filename)
  336.       ok = AskYesNoCancel('%s\n   save this file? ' % final_path)
  337.       if ok == -1:
  338.          status = -1
  339.          break
  340.       elif ok == 0:
  341.          continue
  342.       elif ok == 1:
  343.          status = 1
  344.          break
  345.    final_path = os.path.normpath(final_path)
  346.    return final_path, status
  347.  
  348.  
  349.  
  350.  
  351. def PromptGetFile(prompt='please select a file', directory=''):
  352.    osVisualMethod = update_visualMethod()
  353.  
  354.    ### platform specific file dialogs.
  355.    if osVisualMethod == 'mac':
  356.       import macfs
  357.       fsspec, ok = macfs.PromptGetFile(prompt)
  358.       if ok != 1:
  359.          return '', 0
  360.       path = fsspec.as_pathname()
  361.       path = os.path.normpath(path)
  362.       return path, 1
  363.  
  364.    ### platform specific file dialogs.
  365.    if osVisualMethod == 'tkWin':
  366.       import Tkinter
  367.       import tkFileDialog
  368.       tkTemp  = Tkinter.Tk()
  369.       tkTemp.withdraw()
  370.       options  = {'filetypes':[("all files", "*")], 
  371.                  'initialdir': directory,
  372.                   'title'    : prompt,     
  373.                   'parent'   : tkTemp}
  374.       guiTemp = tkFileDialog.Open()
  375.       guiTemp.options = options
  376.       # filename = apply(tkFileDialog.Open, (), options).show(
  377.       path = guiTemp.show()
  378.       # clean up gui mess
  379.       del guiTemp
  380.       tkTemp.destroy()
  381.       # return path
  382.       if path != '' and path != None:
  383.          path = os.path.normpath(path)
  384.          return path, 1
  385.       else:
  386.          return '', 0
  387.  
  388.    ### for all other platforms
  389.    final_path = ''
  390.    while 1:
  391.       if directory == '':
  392.          directory = CheckDirPath(os.getcwd())
  393.       else:
  394.          directory = CheckDirPath(directory)
  395.  
  396.       header = '\n%s' % directory
  397.       cwd_contents = os.listdir(directory)
  398.       ### print_topics(header, cwd_contents, 0, 72)
  399.       print prompt
  400.  
  401.       status = AskString('name file, change directory, or cancel? (f, cd, c):')
  402.       if status == 'cd' or status == 'CD':
  403.          try:
  404.             path, ok = GetDirectory('', directory)
  405.          except:
  406.             print 'no such directory\n'
  407.             continue
  408.          if ok != 1:
  409.             status = -1
  410.             break
  411.          else:
  412.             directory = path
  413.             continue
  414.       elif status == 'c' or status == 'C':
  415.          break
  416.       else:
  417.          if status != 'f' and status != 'F':
  418.             print '   unidentified input, please try again:'
  419.             continue
  420.          status = 0
  421.          while 1:
  422.             test_filename = AskString('name file?')
  423.             dir_contents = os.listdir(directory)
  424.             if test_filename in dir_contents:
  425.                test_path = directory + test_filename  # only add to test
  426.                ### check to see if file is a folder
  427.                if os.path.isdir(test_path) == 1: #true if is a directory.
  428.                   ok = AskYesNoCancel('this is a directory, not a file. try again? ')
  429.                   if ok == 1:
  430.                      continue
  431.                   elif ok == 0:
  432.                      status = -2
  433.                      break
  434.                   else:
  435.                      break
  436.                final_path = os.path.join(directory,test_filename)  # no os.sep needed
  437.                break
  438.             else:
  439.                ok = AskYesNoCancel('no such file exists. try again? ')
  440.                if ok == 1:
  441.                   continue
  442.                elif ok == 0:
  443.                   status = -2
  444.                   break
  445.                else:
  446.                   break
  447.  
  448.       if status == -2:
  449.          continue
  450.       if final_path == '':
  451.          status = -1
  452.          break
  453.       else:
  454.          ok = AskYesNoCancel('%s\n   select this file? ' % final_path)
  455.          if ok == -1:
  456.             status = -1
  457.             break
  458.          elif ok == 0:
  459.             continue
  460.          elif ok == 1:
  461.             status = 1
  462.             break
  463.    final_path = os.path.normpath(final_path)
  464.    return final_path, status         
  465.  
  466.  
  467. #-----------------------------------------------------------------||||||||||||--
  468. ### general dispaly functions for athenaCL
  469.  
  470.  
  471. def userChooseFromList(prompt, choiceList, sessionType='terminal', parentGUI=None):
  472.    p_list = choiceList
  473.    p_list.sort()
  474.    p_no = len(p_list)
  475.    prompt = prompt + ' (name or number 1-%s):' % p_no
  476.    name = AskString(prompt, sessionType, parentGUI)
  477.    if name == None or name == '': return 0
  478.    if name in p_list:      
  479.       return name
  480.    try:
  481.       p_number = eval(name)
  482.    except:
  483.       return 0
  484.    if p_number <= p_no and p_number >= 1: ##not using actual indexes, but 1+ index
  485.       name = p_list[p_number - 1]
  486.       return name
  487.    else:
  488.       return 0  ## error message
  489.  
  490.  
  491. def graph_str(self, min, max, value):
  492.     if min > max:
  493.         high = min
  494.         low  = max
  495.         rev  = 1
  496.     else:
  497.         high = max
  498.         low  = min
  499.         rev  = 0
  500.     percent = value / float(high)
  501.     if   percent < .025:
  502.         str = '|+---------------------------------------|'
  503.     elif percent >= .025 and percent < .050:
  504.         str = '|-+--------------------------------------|'                  
  505.     elif percent >= .050 and percent < .075:
  506.         str = '|--+-------------------------------------|'  
  507.     elif percent >= .075 and percent < .100:
  508.         str = '|---+------------------------------------|'           
  509.     elif percent >= .100 and percent < .125:
  510.         str = '|----+-----------------------------------|'  
  511.     elif percent >= .125 and percent < .150:
  512.         str = '|-----+----------------------------------|'  
  513.     elif percent >= .150 and percent < .175:
  514.         str = '|------+---------------------------------|'  
  515.     elif percent >= .175 and percent < .200:
  516.         str = '|-------+--------------------------------|'  
  517.     elif percent >= .200 and percent < .225:
  518.         str = '|--------+-------------------------------|'  
  519.     elif percent >= .225 and percent < .250:
  520.         str = '|---------+------------------------------|'  
  521.     elif percent >= .250 and percent < .275:
  522.         str = '|----------+-----------------------------|'  
  523.     elif percent >= .275 and percent < .300:
  524.         str = '|-----------+----------------------------|'  
  525.     elif percent >= .300 and percent < .325:
  526.         str = '|------------+---------------------------|'  
  527.     elif percent >= .325 and percent < .350:
  528.         str = '|-------------+--------------------------|'  
  529.     elif percent >= .350 and percent < .375:
  530.         str = '|--------------+-------------------------|'  
  531.     elif percent >= .375 and percent < .400:
  532.         str = '|---------------+------------------------|'  
  533.     elif percent >= .400 and percent < .425:
  534.         str = '|----------------+-----------------------|'  
  535.     elif percent >= .425 and percent < .450:
  536.         str = '|-----------------+----------------------|'  
  537.     elif percent >= .450 and percent < .475:
  538.         str = '|------------------+---------------------|' 
  539.     elif percent >= .475 and percent < .500:
  540.         str = '|-------------------+--------------------|' 
  541.     elif percent >= .500 and percent < .525:
  542.         str = '|--------------------+-------------------|' 
  543.     elif percent >= .525 and percent < .550:
  544.         str = '|---------------------+------------------|' 
  545.     elif percent >= .550 and percent < .575:
  546.         str = '|----------------------+-----------------|' 
  547.     elif percent >= .575 and percent < .600:
  548.         str = '|-----------------------+----------------|' 
  549.     elif percent >= .600 and percent < .625:
  550.         str = '|------------------------+---------------|' 
  551.     elif percent >= .625 and percent < .650:
  552.         str = '|-------------------------+--------------|' 
  553.     elif percent >= .650 and percent < .675:
  554.         str = '|--------------------------+-------------|' 
  555.     elif percent >= .675 and percent < .700:
  556.         str = '|---------------------------+------------|' 
  557.     elif percent >= .700 and percent < .725:
  558.         str = '|----------------------------+-----------|' 
  559.     elif percent >= .725 and percent < .750:
  560.         str = '|-----------------------------+----------|' 
  561.     elif percent >= .750 and percent < .775:
  562.         str = '|------------------------------+---------|' 
  563.     elif percent >= .775 and percent < .800:
  564.         str = '|-------------------------------+--------|' 
  565.     elif percent >= .800 and percent < .825:
  566.         str = '|--------------------------------+-------|' 
  567.     elif percent >= .825 and percent < .850:
  568.         str = '|---------------------------------+------|' 
  569.     elif percent >= .850 and percent < .875:
  570.         str = '|----------------------------------+-----|' 
  571.     elif percent >= .875 and percent < .900:
  572.         str = '|-----------------------------------+----|' 
  573.     elif percent >= .900 and percent < .925:
  574.         str = '|------------------------------------+---|' 
  575.     elif percent >= .925 and percent < .950:
  576.         str = '|-------------------------------------+--|' 
  577.     elif percent >= .950 and percent < .975:
  578.         str = '|--------------------------------------+-|' 
  579.     elif percent >= .975:
  580.         str = '|---------------------------------------+|' 
  581.                   
  582.     if rev == 1:
  583.         l = list(str)
  584.         l.reverse()
  585.         str = ''
  586.         for letter in l:
  587.             str = str + letter
  588.     ### this symbol may mot work on other systems!
  589.     str = str.replace('+', '+')
  590.     str = str.replace('-', '.')
  591.     return str
  592.  
  593. def getSalutation(localHour, localMin, cursToolFake='[] '):
  594.    if localHour >= 3 and localHour < 5:
  595.       salutation = '[good day.] '
  596.    elif localHour >= 5 and localHour < 12:
  597.       salutation = '[good morning.] '
  598.    elif localHour >= 12 and localHour < 17:
  599.       salutation = '[good afternoon.] '
  600.    elif localHour >= 17 and localHour < 22:
  601.       salutation = '[good evening.] '
  602.    elif localHour >= 22 and localHour < 24:
  603.       salutation = '[evening.] '
  604.    elif localHour >= 0 and localHour < 3:
  605.       salutation = '[welcome.] '
  606.  
  607.    clockHour = localHour%12
  608.    if clockHour == 0 and localHour == 12:
  609.       clockHour = 12
  610.    ## default response:
  611.    if localMin % 2 == 0 or localMin % 3 == 0 or localMin % 5 == 0 or localMin % 7 == 0 or localMin % 9 == 0:
  612.       salutation = cursToolFake
  613.       ### salutation = '[%i.%.2i] ' % (clockHour, localMin)
  614.    if localHour == 4 or localHour == 16:
  615.       if localMin == 20:
  616.          salutation = '[praise to the most high!] '
  617.    return salutation
  618.  
  619.  
  620.  
  621. #-----------------------------------------------------------------||||||||||||--
  622. # strings for error messages!
  623.  
  624. msgBadPmtrFormat       = 'incorrect parameter format.\n' # need return carriage
  625. msgConfusedInput       = 'incomprehensible input, please try again.'
  626. msgIncorrectEntry      = '   incorrect entry. try again.'
  627. msgReturnCancel        = '' #'   .' 
  628. msgModsNotFound        = 'athenaCL cannot find all required modules. please enter the path of the "libATH" directory:'
  629. msgBadAthObj           = '   there is a problem with this AthenaObject file. make sure an AthenaObject has been selected, then try (1) opening the file in a text editor and re-saving the file with the appropriate line endings or (2) restart athenaCL and try again.\n'
  630.  
  631.  
  632. msgSCselectX           = 'please select SC X...'
  633. msgSCselectY           = 'please select SC Y...'
  634.  
  635. msgMCbadMapRange       = '   incorrect map range. enter a start map, a comma, and an end map.'
  636. msgMCbadPosition       = '   incorrect position entry. try again.'
  637. msgMCbadRankRange      = '   incorrect rank range. enter a start rank, a comma, and an end rank.'
  638. msgMCerrorCreatingChord= '   there has been an error creating this chord, please try again.'
  639. msgMCenterRankMethod   = 'enter ranking method: Smoothness, Uniformity or Balance? (s, u, or b):'
  640.  
  641. msgPEnoNamedPE         = 'no such PathEngine exists. enter "PEls" to see all names.\n'  
  642. msgPMcreateFirst       = 'create a multipath first: enter "PMn"\n'
  643.  
  644. msgPInameGet           = 'please name this PathInstance:'
  645. msgPIcreateFirst       = 'create a PathInstance first: enter "PIn".\n'
  646. msgPImissingName       = 'that PathInstance no longer exists: enter "PIo".\n'
  647. msgPIbadName           = 'no such PathInstance exists. enter "PIls" to see all names.\n'
  648. msgPInameTaken         = 'that PI name already exists, please choose another.'
  649.  
  650. msgPVnotAvailable      = 'no PV operations are available.\n'
  651. msgPVgroupMissingName  = 'that PV Group no longer exists: enter "PVo".\n'
  652. msgPVbadName           = 'no such PV Group exists. enter "PVls" to see all names.\n'
  653. msgPVnameTaken         = 'that PV Group name already exists, please choose another.'
  654.  
  655. msgTMbadName           = 'no such TextureModule exists. enter "TMls" to see all names.\n' 
  656.  
  657. msgTIcreateFirst       = 'create a TextureInstance first: enter "TIn".\n'
  658. msgTIselectFirst       = 'select a TextureInstance first: enter "TIo".\n' 
  659. msgTIbadName           = 'no such TextureInstance exists. enter "TIls" to see all names\n'
  660. msgTImissingName       = 'that TextureInstance no longer exists: enter "TIo".\n'
  661. msgTInameTaken         = 'that TI name already exists, please choose another.'
  662. msgTIbadPmtrName       = 'no such parameter exists: enter "TIv" to display parameters.\n'
  663.  
  664. msgTCnameTaken         = 'that TextureClone name already exists, please choose another.'
  665. msgTCcreateFirst       = 'create a TextureClone first: enter "TCn".\n' 
  666. msgTCbadName           = 'no such TextureClone exists. enter "TCls" to see all names.\n'
  667. msgTCbadTimeEntry      = '   a TextureClone cannot start before time 0. enter a more positive timeShift.'
  668.  
  669. msgTTbadName           = 'no such TextureTemperment exists. enter "TTls" to see all names.\n'
  670.  
  671. msgCScreateFirst       = 'create a score first. enter "CSsco".\n'
  672.  
  673. #-----------------------------------------------------------------||||||||||||--
  674.  
  675.  
  676.  
  677. class Print_to_File:
  678.    ''' temporarily redirects standard io (print functions) to a file'''
  679.    def __init__(self, prompt='please name your file:', defaultFilename='name.sco', defaultDirectory='', extension='*'):  # extension should have . in it (.sco)
  680.       self.statusFlag = 0
  681.       while 1:
  682.          try:
  683.             self.file_path, ok = StandardPutFile(prompt, defaultFilename, defaultDirectory, extension)
  684.             if ok == 0:
  685.                self.statusFlag = -1
  686.                break
  687.             self.statusFlag = 1
  688.             break
  689.          except IOError:
  690.             Message('error: file is busy!!\neither close the file or choose a new name.')
  691.  
  692.    def open_FileToPrint(self):
  693.       self.stdout_init = sys.stdout    ### save value of stdout for later
  694.       sys.stdout       = open(self.file_path, 'w')  
  695.    def get_fileNameDir(self):
  696.       filename = os.path.basename(self.file_path)
  697.       return filename, self.file_path       
  698.  
  699.    def close_file(self):
  700.       sys.stdout.close() #/* close std out */
  701.       sys.stdout = self.stdout_init       ### return original value to stdout
  702.       filename = os.path.basename(self.file_path)
  703.       return filename, self.file_path  
  704.  
  705.  
  706. class GetUserFile:
  707.    'class to facilitate writing scores to files'
  708.    def __init__(self, prompt='please name your file:', defaultFilename='name.sco', defaultDirectory='', extension='*'):  # extension should have . in it (.sco)
  709.       self.statusFlag = 0
  710.       while 1:
  711.          try:
  712.             self.file_path, ok = StandardPutFile(prompt, defaultFilename, defaultDirectory, extension)
  713.             if ok == 0:
  714.                self.statusFlag = -1
  715.                break
  716.             self.statusFlag = 1
  717.             break
  718.          except IOError:
  719.             Message('error: file is busy!!\neither close the file or choose a new name.')
  720.  
  721.    def get_fileNameDir(self):
  722.       filename = os.path.basename(self.file_path)
  723.       return filename, self.file_path       
  724.  
  725.    def close_file(self):
  726.       filename = os.path.basename(self.file_path)
  727.       return filename, self.file_path  
  728.  
  729.  
  730.  
  731. if __name__ == '__main__':
  732.    import athenaCL
  733.  
  734.  
  735.  
  736.  
  737.